/*
 * @lc app=leetcode.cn id=2032 lang=typescript
 *
 * [2032] 至少在两个数组中出现的值
 */

// @lc code=start
function twoOutOfThree(
    nums1: number[],
    nums2: number[],
    nums3: number[]
): number[] {
    let total = new Map<number, number>();
    const go = (nums: number[]) => {
        let now = new Set<number>();
        nums.forEach((i) => {
            if (now.has(i)) return;
            now.add(i);
            total.set(i, (total.get(i) || 0) + 1);
        });
    };
    go(nums1);
    go(nums2);
    go(nums3);
    return [...total.entries()].filter(([_, num]) => num >= 2).map((i) => i[0]);
}
// @lc code=end
